public class StringDemo {
    public static void main(String[] args) {
        m7();
    }

    private static void m0() {
        String a = "a";
        String b = "b";
        String s = a + b;
        String intern = s.intern();
        System.out.println(s == intern);
    }

    private static void m1() {
        String a = "a";
        String b = "b";
        String ab = "ab";
        String s = a + b;
        String intern = s.intern();
        System.out.println(s == intern);
    }

    private static void m2() {
        String s = new String("a") + new String("b");
        String intern = s.intern();
        System.out.println(s == intern);
    }

    private static void m3() {
        String a = "a";
        String ab1 = a + "b";
        String ab2 = "ab";
        System.out.println(ab1 == ab2);
    }

    private static void m4() {
        String a = "a";
        String b = "b";
        String ab1 = a + b;
        String ab2 = "ab";
        System.out.println(ab1 == ab2);
    }

    private static void m5() {
        final String a = "a";
        String ab1 = a + "b";
        String ab2 = "ab";
        System.out.println(ab1 == ab2);
    }

    private static void m6() {
        String ab1 = "ab";
        String ab2 = new String("ab");
        String ab3 = new String("ab");
        System.out.println(ab2 == ab1.intern());
        System.out.println(ab2 == ab3.intern());
        System.out.println(ab2.intern() == ab3.intern());
        System.out.println(ab1 == ab3.intern());
    }

    private static void m7() {
        String a = "a";
        String b = "b";
        String ab1 = a + b;
        String ab2 = a + b;
        System.out.println(ab1 == ab2);
        System.out.println(ab1 == ab1.intern());
        System.out.println(ab2 == ab2.intern());
        System.out.println(ab1 == ab2.intern());
        System.out.println(ab1.intern() == ab2.intern());
    }

}
